home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.12 Dec 95 / Tips / 11.12 Tips next >
Encoding:
Text File  |  1995-11-10  |  5.6 KB  |  108 lines  |  [TEXT/R*ch]

  1.  
  2. Arguments To “s” In MacsBug
  3. In MacsBug, the s [step] command will take an argument which is either a count or a condition on which to stop. This can be very useful for unwinding a twisty bit of code. For example, if you keep crashing in a particular spot, but you can’t tell how you got there or what happened just before, you can break before everything goes wrong and type
  4.  
  5.  
  6.          s (pc == <badspot>)
  7.  
  8. Where badspot is where you know things are wrong. Macsbug will step through all of the instructions in between here and there. You can then examine the path taken in the scrollback or, if you turn on the log first, look at it all offline with an editor. With the newest versions of MacsBug, you can even step over mixed mode. Note that it’s possible for find weirder problems, too:
  9.  
  10.  
  11.         s (a0 == 0)
  12.  
  13. will step until a0 equals 0.
  14.  
  15.  
  16.         s (<addr>^ != <current value>)
  17.  
  18. will step until the long at <addr> changes.
  19.  
  20. You can use this trick to find a really wide variety of problems. Should you use this tip, donate my fee to the American Red Cross.
  21.  
  22.  – Tim Dierks
  23.  
  24.  
  25.  
  26.  
  27.  They Said I Couldn’t 
  28. Return Errors From Constructors
  29. I have read several times that “you can’t return an error from a constructor”. This is not entirely true. See the following code example:
  30.  
  31. class exampleClass : parentClass
  32. {
  33.   exampleClass( int arg1, OSErr& errOut );
  34.     // initialization constructor
  35. ...etc....
  36. };
  37.  
  38. exampleClass::exampleClass( int arg1, OSErr& errOut )
  39.  : parentClass()  // parent class constructor explicitly called
  40.  , memberData() // instance variable's explict constructor
  41. {
  42. //  errOut = noErr;  see note #4 below
  43.   errOut = someSystemCall( arg1 );
  44. }
  45.  
  46. void main ( void )
  47. {
  48.    OSErr  err;
  49.    exampleClass  aVar( 12, err );
  50.    if ( err != noErr ) 
  51.    {....etc....
  52. }
  53. This example “obviously” returns error information.
  54. However, errOut will NOT have a known value if the following occurs:
  55.  
  56. 1.    parentClass’s explicit constructor throws an exception.
  57. 2.    memberData’s explicit constructor throws an exception.
  58. 3.    someSystemCall throws an exception. This example used explicit contructor calls, but the same is true for  implicit constructor calls to parent classes and member data varables.
  59. 4.    if the errOut = noErr line is uncommented, then at least errOut can have a known value in the absence of other exceptions.
  60.  
  61. Of course, since main isn’t doing try/catch, then the test of err != noErr is not going to happen when an exception occurs, either.
  62. – C. Keith Ray
  63.  
  64. Is Your App Windowshade Savvy?
  65. Many apps change the cursor within certain areas of their windows. This may be to provide the crosshairs in a drawing window, or a hand cursor if something can be dragged in an area of your window. Unfortunately, many applications forget to check whether their window is windowshaded or not. If their window is windowshaded but still the front window, they go ahead and change the cursor anyway, leading to the effect of the cursor changing over “empty space.” Looks ugly. Here’s the fix:
  66.  
  67. if (EmptyRgn( ((WindowPeek)TheWindow)->contRgn )) 
  68. //window shade has been used
  69.     Don’t change the cursor;
  70. else
  71.     Go ahead and change the cursor;
  72.  
  73. In the above example, TheWindow is the windowptr to the window who’s areas we are changing the cursor for.
  74.  
  75. – Richard Unger and Eric Bourque
  76.  
  77. Shortcut to Open Header Files In CodeWarrior
  78. Here is a feature that I’d long hoped for, and recently, by accident, found.
  79. In Metrowerk’s IDE, typing ‘command tab’ will open the corresponding .h or .cp file.  For example, if you’re working in a source file named “FileName.cp” typing ‘command tab’ will open “FileName.h”.  This is an extremely useful feature that I hope Symantec will adopt.
  80. – Norman Basham
  81. Drop Into MacsBug at a Predictable Address
  82. When dropping into MacsBug, I often find myself in the wrong application’s code.  For example, lets say I want to force-quit the finder using “es” from MacsBug.  (command-option-escape will quit and then restart the Finder).  To make sure the Finder is the frontmost app, I hold the mouse down in one of the Finder’s menus and press the interrupt key, and I’m dropped in at a known location (a small loop within the menu manager).  Not only that, but the current menu manager is emulated on PowerMacs, further ensuring my safety.  Then a simple “es” quits the Finder.
  83. – Damon Cokenias
  84.  
  85. Lock Your Libraries, Prevent Changes
  86. Here’s a tip that may be obvious, but it’s  useful, if somewhat simple.
  87. If you don’t want to modify the standard libraries included in a development environment (the source to PowerPlant or TCL for example) you can use the following script to lock all the files.  I use this script in MPW, but should work with ToolServer as well:
  88.  
  89. ### First set the current directory to the folder containing the sources to lock
  90. ### note that this script does sub-folders also.
  91. ### replace "xxx" with your path, e.g., "HD:MPW:Interfaces:"
  92. directory "Full path to the folder in which the files are:"
  93.  
  94. ### Then set the lock bit to ON for all files which are of
  95. ### type 'TEXT' in the current directory and all sub-directories
  96. ### Notes:
  97. ###   remove "-r" to skip sub-directories
  98. ###   make the "L" lowercase ("l") to un-lock files
  99. ###   the -f is for full paths, -s to supress directory listings
  100. SetFile -a L `files -r -f -s -t 'TEXT'`
  101.  
  102. Anyway, just thought I’d pass it on.  It’s particularly useful while using a class browser like Object Master, where you can browse all classes and it’s easy to end up editing one of the supplied classes in PowerPlant/Think Class Library/MacApp.
  103.  
  104. – Tyler Morrison
  105.  
  106. [AppleScript also supports locking and unlocking of files.  Simply modify the “locked” property of x, where x is a file alias or file name with: set the locked of file x to true 
  107. EdAsst – jtk]
  108.